package com.smile.db.operation;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.smile.db.DBHelper;
import com.smile.model.RegisterBean;

public class LoginOperation {

	private static final LoginOperation LO = new LoginOperation();

	private LoginOperation() {
	}

	public static LoginOperation getLO() {
		return LO;
	}

	public String login(RegisterBean registerBean) {
		
		String sql = "select u_nickname, u_password from user where u_name='" + registerBean.getName()
				+ "'";
		try {
			ResultSet result = DBHelper.query(sql);
			System.out.println("登录");
			if (result.next()) {
				if (result.getString("u_password").equals(registerBean.getPassword())) {
					System.out.println("登录成功");
					return "1@" + result.getString("u_nickname");
				} else {
					return "-1@2";
				}
			} else {
				return "-1@3";
			}
			
			
		} catch (SQLException e) {
			System.out.println(e.getMessage());
			return "-1@" + e.getErrorCode();
		}
	}
}
